<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="企业名称" prop="enterpriseName">
        <el-input
          v-model="queryParams.enterpriseName"
          placeholder="请输入企业名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="统一社会信用代码" prop="enterpriseId">
        <el-input
          v-model="queryParams.enterpriseId"
          placeholder="请输入统一社会信用代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label=" 是否涉及危险化学品进口: 0否，1是" prop="importExist">
        <el-input
          v-model="queryParams.importExist"
          placeholder="请输入 是否涉及危险化学品进口: 0否，1是"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区域：上海市企业必填" prop="area">
        <el-input
          v-model="queryParams.area"
          placeholder="请输入区域：上海市企业必填"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属街道：上海市企业必填" prop="street">
        <el-input
          v-model="queryParams.street"
          placeholder="请输入所属街道：上海市企业必填"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地址区域：外省市企业必填" prop="outerAddress">
        <el-input
          v-model="queryParams.outerAddress"
          placeholder="请输入地址区域：外省市企业必填"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="实际运营地址" prop="realAddress">
        <el-input
          v-model="queryParams.realAddress"
          placeholder="请输入实际运营地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经度" prop="lng">
        <el-input
          v-model="queryParams.lng"
          placeholder="请输入经度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="纬度" prop="lat">
        <el-input
          v-model="queryParams.lat"
          placeholder="请输入纬度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="进口商企业名称" prop="importEnterpriseName">
        <el-input
          v-model="queryParams.importEnterpriseName"
          placeholder="请输入进口商企业名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="进口商运营地址" prop="importEnterpriseAddress">
        <el-input
          v-model="queryParams.importEnterpriseAddress"
          placeholder="请输入进口商运营地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="登陆账号" prop="account">
        <el-input
          v-model="queryParams.account"
          placeholder="请输入登陆账号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input
          v-model="queryParams.password"
          placeholder="请输入密码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经办人姓名" prop="registerName">
        <el-input
          v-model="queryParams.registerName"
          placeholder="请输入经办人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经办人手机号" prop="registerMobile">
        <el-input
          v-model="queryParams.registerMobile"
          placeholder="请输入经办人手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经办人邮箱" prop="registerEmail">
        <el-input
          v-model="queryParams.registerEmail"
          placeholder="请输入经办人邮箱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="国内联系人姓名" prop="domesticRegisterName">
        <el-input
          v-model="queryParams.domesticRegisterName"
          placeholder="请输入国内联系人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="国内联系人手机" prop="domesticRegisterMobile">
        <el-input
          v-model="queryParams.domesticRegisterMobile"
          placeholder="请输入国内联系人手机"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="国内联系人邮箱" prop="domesticRegisterEmail">
        <el-input
          v-model="queryParams.domesticRegisterEmail"
          placeholder="请输入国内联系人邮箱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['trace:yiqiEnterprise:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['trace:yiqiEnterprise:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['trace:yiqiEnterprise:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['trace:yiqiEnterprise:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="yiqiEnterpriseList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="${comment}" align="center" prop="id" />
      <el-table-column label="企业名称" align="center" prop="enterpriseName" />
      <el-table-column label="统一社会信用代码" align="center" prop="enterpriseId" />
      <el-table-column label="企业类型:危险化学品生产企业、危险化学品经营企业、危险化学品存储企业、危险化学品使用企业" align="center" prop="type" />
      <el-table-column label=" 是否涉及危险化学品进口: 0否，1是" align="center" prop="importExist" />
      <el-table-column label="区域分类：上海市、外省市、国外" align="center" prop="areaType" />
      <el-table-column label="区域：上海市企业必填" align="center" prop="area" />
      <el-table-column label="所属街道：上海市企业必填" align="center" prop="street" />
      <el-table-column label="地址区域：外省市企业必填" align="center" prop="outerAddress" />
      <el-table-column label="实际运营地址" align="center" prop="realAddress" />
      <el-table-column label="经度" align="center" prop="lng" />
      <el-table-column label="纬度" align="center" prop="lat" />
      <el-table-column label="进口商企业名称" align="center" prop="importEnterpriseName" />
      <el-table-column label="进口商运营地址" align="center" prop="importEnterpriseAddress" />
      <el-table-column label="许可证" align="center" prop="licenseFile" />
      <el-table-column label="登记证" align="center" prop="importLicenseFile" />
      <el-table-column label="登陆账号" align="center" prop="account" />
      <el-table-column label="密码" align="center" prop="password" />
      <el-table-column label="经办人姓名" align="center" prop="registerName" />
      <el-table-column label="经办人手机号" align="center" prop="registerMobile" />
      <el-table-column label="经办人邮箱" align="center" prop="registerEmail" />
      <el-table-column label="国内联系人姓名" align="center" prop="domesticRegisterName" />
      <el-table-column label="国内联系人手机" align="center" prop="domesticRegisterMobile" />
      <el-table-column label="国内联系人邮箱" align="center" prop="domesticRegisterEmail" />
      <el-table-column label="状态" align="center" prop="status" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['trace:yiqiEnterprise:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['trace:yiqiEnterprise:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改企业信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="企业名称" prop="enterpriseName">
          <el-input v-model="form.enterpriseName" placeholder="请输入企业名称" />
        </el-form-item>
        <el-form-item label="统一社会信用代码" prop="enterpriseId">
          <el-input v-model="form.enterpriseId" placeholder="请输入统一社会信用代码" />
        </el-form-item>
        <el-form-item label=" 是否涉及危险化学品进口: 0否，1是" prop="importExist">
          <el-input v-model="form.importExist" placeholder="请输入 是否涉及危险化学品进口: 0否，1是" />
        </el-form-item>
        <el-form-item label="区域：上海市企业必填" prop="area">
          <el-input v-model="form.area" placeholder="请输入区域：上海市企业必填" />
        </el-form-item>
        <el-form-item label="所属街道：上海市企业必填" prop="street">
          <el-input v-model="form.street" placeholder="请输入所属街道：上海市企业必填" />
        </el-form-item>
        <el-form-item label="地址区域：外省市企业必填" prop="outerAddress">
          <el-input v-model="form.outerAddress" placeholder="请输入地址区域：外省市企业必填" />
        </el-form-item>
        <el-form-item label="实际运营地址" prop="realAddress">
          <el-input v-model="form.realAddress" placeholder="请输入实际运营地址" />
        </el-form-item>
        <el-form-item label="经度" prop="lng">
          <el-input v-model="form.lng" placeholder="请输入经度" />
        </el-form-item>
        <el-form-item label="纬度" prop="lat">
          <el-input v-model="form.lat" placeholder="请输入纬度" />
        </el-form-item>
        <el-form-item label="进口商企业名称" prop="importEnterpriseName">
          <el-input v-model="form.importEnterpriseName" placeholder="请输入进口商企业名称" />
        </el-form-item>
        <el-form-item label="进口商运营地址" prop="importEnterpriseAddress">
          <el-input v-model="form.importEnterpriseAddress" placeholder="请输入进口商运营地址" />
        </el-form-item>
        <el-form-item label="许可证">
          <file-upload v-model="form.licenseFile"/>
        </el-form-item>
        <el-form-item label="登记证">
          <file-upload v-model="form.importLicenseFile"/>
        </el-form-item>
        <el-form-item label="登陆账号" prop="account">
          <el-input v-model="form.account" placeholder="请输入登陆账号" />
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="form.password" placeholder="请输入密码" />
        </el-form-item>
        <el-form-item label="经办人姓名" prop="registerName">
          <el-input v-model="form.registerName" placeholder="请输入经办人姓名" />
        </el-form-item>
        <el-form-item label="经办人手机号" prop="registerMobile">
          <el-input v-model="form.registerMobile" placeholder="请输入经办人手机号" />
        </el-form-item>
        <el-form-item label="经办人邮箱" prop="registerEmail">
          <el-input v-model="form.registerEmail" placeholder="请输入经办人邮箱" />
        </el-form-item>
        <el-form-item label="国内联系人姓名" prop="domesticRegisterName">
          <el-input v-model="form.domesticRegisterName" placeholder="请输入国内联系人姓名" />
        </el-form-item>
        <el-form-item label="国内联系人手机" prop="domesticRegisterMobile">
          <el-input v-model="form.domesticRegisterMobile" placeholder="请输入国内联系人手机" />
        </el-form-item>
        <el-form-item label="国内联系人邮箱" prop="domesticRegisterEmail">
          <el-input v-model="form.domesticRegisterEmail" placeholder="请输入国内联系人邮箱" />
        </el-form-item>
        <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listYiqiEnterprise, getYiqiEnterprise, delYiqiEnterprise, addYiqiEnterprise, updateYiqiEnterprise } from "@/api/trace/yiqiEnterprise";

export default {
  name: "YiqiEnterprise",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 企业信息表格数据
      yiqiEnterpriseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        enterpriseName: null,
        enterpriseId: null,
        type: null,
        importExist: null,
        areaType: null,
        area: null,
        street: null,
        outerAddress: null,
        realAddress: null,
        lng: null,
        lat: null,
        importEnterpriseName: null,
        importEnterpriseAddress: null,
        licenseFile: null,
        importLicenseFile: null,
        account: null,
        password: null,
        registerName: null,
        registerMobile: null,
        registerEmail: null,
        domesticRegisterName: null,
        domesticRegisterMobile: null,
        domesticRegisterEmail: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        enterpriseName: [
          { required: true, message: "企业名称不能为空", trigger: "blur" }
        ],
        enterpriseId: [
          { required: true, message: "统一社会信用代码不能为空", trigger: "blur" }
        ],
        type: [
          { required: true, message: "企业类型:危险化学品生产企业、危险化学品经营企业、危险化学品存储企业、危险化学品使用企业不能为空", trigger: "change" }
        ],
        importExist: [
          { required: true, message: " 是否涉及危险化学品进口: 0否，1是不能为空", trigger: "blur" }
        ],
        areaType: [
          { required: true, message: "区域分类：上海市、外省市、国外不能为空", trigger: "change" }
        ],
        lng: [
          { required: true, message: "经度不能为空", trigger: "blur" }
        ],
        lat: [
          { required: true, message: "纬度不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询企业信息列表 */
    getList() {
      this.loading = true;
      listYiqiEnterprise(this.queryParams).then(response => {
        this.yiqiEnterpriseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        enterpriseName: null,
        enterpriseId: null,
        type: null,
        importExist: null,
        areaType: null,
        area: null,
        street: null,
        outerAddress: null,
        realAddress: null,
        lng: null,
        lat: null,
        importEnterpriseName: null,
        importEnterpriseAddress: null,
        licenseFile: null,
        importLicenseFile: null,
        account: null,
        password: null,
        registerName: null,
        registerMobile: null,
        registerEmail: null,
        domesticRegisterName: null,
        domesticRegisterMobile: null,
        domesticRegisterEmail: null,
        status: "0",
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加企业信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getYiqiEnterprise(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改企业信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateYiqiEnterprise(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addYiqiEnterprise(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除企业信息编号为"' + ids + '"的数据项？').then(function() {
        return delYiqiEnterprise(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('trace/yiqiEnterprise/export', {
        ...this.queryParams
      }, `yiqiEnterprise_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
